export function isObject(obj) {
  return isType('Object')(obj)
}

export function isArray(obj) {
  return isType('Array')(obj)
}

export function isBoolean(obj) {
  return isType('Boolean')(obj)
}

export function isNumber(obj) {
  return isType('Number')(obj)
}

export function isString(obj) {
  return isType('String')(obj)
}

export function isType(type) {
  return function (obj) {
    return Object.prototype.toString.call(obj) === '[object ' + type + ']'
  }
}

/**
 * 简单-表单清空 支持深级操作
 * @param form
 */
export function simpleClearForm(form) {
  if(!form) return
  const keys = Object.keys(form)
  keys.forEach(key => {
    const val = form[key]
    if (isBoolean(val)) {
      form[key] = false
    } else if (isArray(val)) {
      form[key] = []
    } else if (isObject(val)) {
      simpleClearForm(form[key])
    } else {
      form[key] = ''
    }
  })
}

export function UUID() {
  const s = []
  const hexDigits = '0123456789abcdef'
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  }
  s[14] = '4'
  s[19] = hexDigits.substring(s[19] & 0x3 | 0x8, 1)
  s[8] = s[13] = s[18] = s[23] = '-'

  const uuid = s.join('')
  return uuid
  // return Math.random().toString(36).substring(3, 8)

}
